const utils = {
  toJSON(o) {
    return JSON.stringify(o, (k, v) => {
      return ['function', 'object'].includes(typeof v) ? undefined : v
    })
  },
  type(o) {
    return Object.prototype.toString.call(o).slice(8, -1).toLowerCase()
  },
  isInTypes(o, types) {
    return types.map(t => t.toLowerCase()).includes(utils.type(o))
  }
}

function extendUtils() {
  `Number,String,Null,Undefined,BigInt,Symbol,
Array,Object,Function,RegExp,Date
Map,Set,WeakMap,WeakSet,WeakWeakSet,
  `
    .trim()
    .split(',')
    .filter(v => v)
    .map(typeName => {
      typeName = typeName.trim()
      utils['is' + typeName] = (o) => {
        return Object.prototype.toString.call(o).slice(8, -1) === typeName
      }
    })
}

extendUtils()

export default utils
